//
//  HYXloginViewModel.m
//  SpeSmartUnitTester_Example
//
//  Created by Points on 2020/8/15.
//  Copyright © 2020 hfqf123. All rights reserved.
//

#import "HYXloginViewModel.h"
#import "HYXRegister2ViewController.h"
@interface HYXloginViewModel()

@end

@implementation HYXloginViewModel



#pragma mark - 登录页面
- (void)loginBtnClicked{
    [HYXHttpPushExtensionFactory factory].
    setPath(@"http://127.0.0.1:18080/unittest/login/login")
    .setNeedToast(NO)
    .setResponseBlock(^(id<HYXHttpResponseModel> resp) {
        HYXHttpResonseModule *ret = (HYXHttpResonseModule *)resp;
        if(ret.state.integerValue == 0){
//           [super onUnitTestCommitedBlock];
        }else{
            
        }
        
    }).setErrorBock(^(id<HYXHttpFailModel> error) {
        
    }).post();
}

- (void)registerBtnClicked{
#if NEED_UNITTEST
     [super onUnitTestCommitedBlock];
#else
      HYXRouterControllerModel *target = [HYXRouterControllerModel from:@"HYXRegister2ViewController"
                                                                 navi:self.controller.navigationController
                                                      objectPropertys:@{
                                                          
                                                      }
                                                         intPropertys:nil
                                                        boolPropertys:@{
                                                            Router_HidesBottomBar:@(YES)
                                                        }];
    HYXROUTER.open(target).then(^(id  _Nonnull resp) {
       
    });
#endif
}


#pragma 注册页面mock
- (void)reloadWithMockData4Register{
    HYXRegister2ViewController *vc = (HYXRegister2ViewController *)self.controller;
    [vc.account setText:self.controller.mockData[@"account"]];
    
    [vc.pwd setText:self.controller.mockData[@"pwd"]];
    [vc.confirmpwd setText:self.controller.mockData[@"pwd2"]];
}

- (void)requestCodeBtnClicked{
    HYXRegister2ViewController *vc = (HYXRegister2ViewController *)self.controller;

    [HYXHttpPushExtensionFactory factory].
    setPath(@"http://127.0.0.1:18080/unittest/login/requestCode")
    .setNeedToast(NO)
    .setResponseBlock(^(id<HYXHttpResponseModel> resp) {
        HYXHttpResonseModule *ret = (HYXHttpResonseModule *)resp;
        if(ret.state.integerValue == 0){
            [super onUnitTestCommitedBlock];
            [vc.verifyCode setText:ret.result[@"code"]];
        }else{
            
        }
        
    }).setErrorBock(^(id<HYXHttpFailModel> error) {
        
    }).post();
}

- (void)registerCommitBtnClicked{
    [HYXHttpPushExtensionFactory factory].
    setPath(@"http://127.0.0.1:18080/unittest/login/register")
    .setNeedToast(NO)
    .setResponseBlock(^(id<HYXHttpResponseModel> resp) {
        HYXHttpResonseModule *ret = (HYXHttpResonseModule *)resp;
        if(ret.state.integerValue == 0){
            [super onUnitTestCommitedBlock];
            
//            [self.controller.navigationController popViewControllerAnimated:YES];
            
        }else{
            
        }
        
    }).setErrorBock(^(id<HYXHttpFailModel> error) {
        
    }).post();
}

#pragma mark - HYXUnitTestBaseViewModelProtocol

- (void)onGetMockData{
 
}

- (void)onStartExcuteBussnessLogic{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self loginBtnClicked];
    });
}
@end
